Let's assume we have a query builder service B that spits out mongo db query when called. This query is received by service A and it executes it as is with mongo db official nodejs driver.
How do I send something like :
[{
_id: new mongo.ObjectID("5f3258cfbaaccedaa5dd2d96"),
phone: "666"
}, {
_id: new mongo.ObjectID("5f3258cfbaaccedaa5dd2da2"),
phone: "555"
}]
from service B to service A?
EDIT:
The following works perfectly fine:
var q = { _id: new mongo.ObjectID("5f3258cfbaaccedaa5dd2d96") };
const result = await this.db.collection("persons").find(q).toArray();
The following doesn't work:
var q = { _id: { $oid: "5f3258cfbaaccedaa5dd2d96" } }
const result = await this.db.collection("persons").find(q).toArray();
Now,
var q = { _id: new mongo.ObjectID("5f3258cfbaaccedaa5dd2d96") };
JSON.stringify(q)
gives you : {"_id":"5f3258cfbaaccedaa5dd2d96"} and if you pass this to service A. You can not use it in service A as follows:
const result = await this.db.collection("persons").find(qStr).toArray();
Or as,
const result = await this.db.collection("persons").find(JSON.parse(qStr)).toArray();
var q = { _id: new mongo.ObjectID("5f3258cfbaaccedaa5dd2d96") }; const result = await this.db.collection("persons").find(q).toArray();is used?service A?