简体   繁体   English

Realm JS:查询字符串列表中的字符串(Mongo等效于elemMatch)

[英]Realm JS : querying a string inside a list of string (Mongo equivalent to elemMatch)

Say I have a collection Pastries like this : 说我有一个这样的糕点集合:

[
    { 
    name: "chocolate",
    theyLikeIt : [{value:"Paul"}, {value:"Oliver"}, {value:"John"}]
    },
    { 
    name: "banana",
    theyLikeIt : [{value:"Sarah"}, {value:"John"}]
    }
]

How could I retrieve all the pastries that John likes ? 我怎么能找到约翰喜欢的所有糕点? In Mongo it would be something like : 在Mongo中,它将类似于:

find({ theyLikeIt: { $elemMatch: { $eq: JohnId } } })

You can use a "dot-notation" to query on child objects. 您可以使用“点符号”查询子对象。 So you should be able to write something like this: 因此,您应该能够编写如下内容:

realm.objects('Person').filtered('theyLikeIt.value = "John"');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM