Sunday, 4 June 2017

Find Document by ObjectID inside Array with CosmosDB and MongoDB API

I'm trying to find a Document by ObjectID inside an array using CosmosDB and Mongoose and it isn't working.

Schema:

...
uid: [{type: mongoose.Schema.Types.ObjectId, ref: 'User'}]
...

Find query in MongoDB

...
db.Score.find({uid: user._id}).exec(function(err, scoreList){
...

This query works with MongoDB but isn't working with CosmosDB, it returns 0 Documents.


If you are not using a Schema you use this Find query:

db.getCollection('scores').find({'uid': { $elemMatch: { $oid: user._id } } })



via Iván Nicolás Liszewski

No comments:

Post a Comment