javascript - Mongoose Query Using Multiple ObjectIds (with 'ref') -
Is it possible to do a query in Mimosa, in which two search criteria are ObjectIds (a referee)?
For example, the following schemas are given:
var objectID = mongosse Sema Object ID; Var fooSchema = new Mongoose Sema ({...}); Schema Fu = mongos Model ("Foo", Fushama, "Foo"); Var barSchema = New mongosse Sema ({Fuide: {Object, Ref: "Foo"}, ...}); Schema Bars = Mongos Model ("bar", barshma, "bar");
I hope to do this work:
schemas.Bar.find ({_id: mongoose.Types.ObjectId (req.params.barId) , FooId: mongoose.Types.ObjectId (req.params.fooId)}, function (fault, result) {...});
But it gives an empty set. Oddly, if I remove one or the other criterion, then it works.
schema.barfund ({_id: mongoose.Types.ObjectId (req.params.barId)}, .. ..);
or ...
schemas.Bar.find ({fooId: mongoose.Types.ObjectId (req.params.fooId)}, .. .);
What am I doing wrong here? I can see raw data in the database, even if the objects in the query use both, then the query is always empty.
Thank you very much
Good, I have a few hours of stare at my screen After that it has solved.
When you insert a document once, you have to explicitly give the Mongoose a ref value in question, it appears that there is also an Object Ed, even if the value came from a FU example where _ID Object ID is defined as! Go figure..I think Manguos connects it to another form of string?
(new schema Bars ({fooId: mongoose.Types.ObjectId (some prefunded FU.ID), ...})) .ave (...)
< / Pre>Finally, it works! Hope this helps others to hang around!
Comments
Post a Comment