1

I'm making request to CosmosDB database via MongoDB adapter from HapiJS server. My request looks like so:

        dbo
          .collection("storage")
          .find(query, function(
            findErr,
            result
          ) {
            if (findErr) throw findErr;
            (async function() {
              output = result.toArray()
            })();
          });

And it works allright. But if I'm trying to add projection (from official docs) nothing changing at all. I'm adding projection like this:

  .find(query, {data:false}, function( ...

What am I missing?

Stennie
  • 63,885
  • 14
  • 149
  • 175
Justice47
  • 682
  • 6
  • 16

2 Answers2

0

Based on the mongodb query syntax listed here, only query filter need to be defined. So you could adjust your code like:

var query = { "data": false };
dbo.collection("storage").find(query, function(
            findErr.....
Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • But I've got another data in query, by which the find is executed: ` query={ type: "Sometype", id:123} ` – Justice47 Aug 19 '19 at 07:33
  • @Justice47 How's your `query` like? – Jay Gong Aug 19 '19 at 07:34
  • its actuallty called mongodb projection - https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/ – Justice47 Aug 19 '19 at 07:52
  • And this is example from CosmosDB docs - `db.families.find( { id: "WakefieldFamily" }, { children: true } )` https://learn.microsoft.com/en-us/azure/cosmos-db/tutorial-query-mongodb – Justice47 Aug 19 '19 at 07:56
0

Seems like my question is duplicate to this, It is worked like so:

 .find(query, {projection:{data:false}}...
Justice47
  • 682
  • 6
  • 16