Storing a query in Mongo

后端 未结 4 1767
南笙
南笙 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 10:57

    Your approach of storing the query as a JSON object in MongoDB is not viable.

    You could potentially store your query logic and fields in MongoDB, but you have to have an external app build the query with the proper MongoDB syntax.

    MongoDB queries contain operators, and some of those have special characters in them.

    There are rules for mongoDB filed names. These rules do not allow for special characters. Look here: https://docs.mongodb.org/manual/reference/limits/#Restrictions-on-Field-Names

    The probable reason you can sometimes successfully create the doc using Robomongo is because Robomongo is transforming your query into a string and properly escaping the special characters as it sends it to MongoDB.

    This also explains why your attempt to update them never works. You tried to create a document, but instead created something that is a string object, so your update conditions are probably not retrieving any docs.

提交回复
热议问题