开发者

Dot Notation in Node JS MongoDb queries

Is it possible to use Dot Notation when dealing with nested documents?

http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects)

I'm trying to query the results of a map/reduce and therefore need to run a query l开发者_运维百科ike this:

find({'_id.page' : 'ThisPage', '_id.user' : 'AUser'}) 

Trying this in Node code returns no rows but the same query works as expected in mongodb shell.


Dot notation isn't required for reaching inside of documents for queries, you can use document notation instead.

find({'_id.page' : 'ThisPage', '_id.user' : 'AUser'})

could instead be

find({_id: {page: 'ThisPage', user: 'AUser'}})


It is very possible, I've done it before.

Why do you have nested documents under your _id property? Not sure what your use case is but that seems a bit strange. _id is a special property that is always the unique id of the document. So it might be getting treated special by the driver (i.e. doesn't expect there to be sub documents). Maybe try putting your sub-documents under a different property name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜