C# mongo queries with json strings

后端 未结 2 1218
陌清茗
陌清茗 2020-12-14 21:03

This seems so basic that I\'m sure I\'ve just overlooked a class or a method somewhere, but for the life of me, I can\'t find it.

I\'ve got a json string like so:

2条回答
  •  萌比男神i
    2020-12-14 21:40

    To add to Shaun McCarthy's answer there's a slightly cleaner way to achieve the exact same goal using BsonDocument.Parse together with QueryDocument:

    var json = "{ SendId: 4, 'Events.Code' : { $all : [2], $nin : [3] } }";
    collection.Find(new QueryDocument(BsonDocument.Parse(json)));
    

提交回复
热议问题