Storing a query in Mongo

后端 未结 4 1774
南笙
南笙 2021-01-13 10:39

This is the case: A webshop in which I want to configure which items should be listed in the sjop based on a set of parameters. I want this to be configurable, because that

4条回答
  •  灰色年华
    2021-01-13 11:13

    I see two problems with your approach.

    In following query

    db.queries.insert({
       "name" : "query1",
       "query": { the thing printed above starting with "$or"... }
    })
    

    a valid JSON expects key, value pair. here in "query" you are storing an object without a key. You have two options. either store query as text or create another key inside curly braces.

    Second problem is, you are storing query values without wrapping in quotes. All string values must be wrapped in quotes.

    so your final document should appear as

    db.queries.insert({
        "name" : "query1",
        "query": 'the thing printed above starting with "$or"... '
    })
    

    Now try, it should work.

提交回复
热议问题