MongoError: cannot infer query fields to set, path 'users' is matched twice

Related searches

I am using mongoose. I want to create a document chat with an array users (including userId1, userId2), if I do not find it:

This is how I do:

ChatModel.findOneAndUpdate(
  { users: { $all: [userId1, userId2] }},
  { $setOnInsert: {
    users: [userId1, userId2]
  }},
  { upsert: true })
  .exec()
  .catch(err => console.log(err));

But I got the error:

MongoError: cannot infer query fields to set, path 'users' is matched twice

This is Chat Schema:

{
  users: [{ type: Schema.Types.ObjectId, ref: 'User' }],
  createdAt: { type: Date, default: Date.now }
}

How can I do it correctly? Thanks


I use this as the condition

{
  "users": {
        $all: [
          {"$elemMatch": userId1},
          {"$elemMatch": userId2}
        ]
  }......
}

Cannot infer query fields to set error on insert, match { [MongoError: exception: cannot infer query fields to set, path 'users' is the engine cannot work out ( presently ) which position to present. that contains "both" those elements as well as the other query conditions. Lets say I have the below record in the `Groups` collection: ``` { "_id" : ObjectId("5899aa7cf226640ba4023c8f"), "members" : [ "a", "b" ] } ``` Then if I do query


There is a workaround for this issue:

db.foo.update({a:{$all:[{$elemMatch:{$eq:0}},{$elemMatch:{$eq:1}}]}},{$set:{b:1}},{upsert:true})

This will match when a is an array with both 0 and 1 in it and it will upsert otherwise.

From: https://jira.mongodb.org/browse/SERVER-13843?focusedCommentId=2305903&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-2305903

"cannot infer query fields to set" - help, However meteor is complaining cannot infer query fields to set, both paths 'entity' and 'entityId' are matched . Any clues what is going on here? However, that's terribly verbose as you have to manually define all the fields you want to fetch, and there are quite a lot with connection types. We're also losing a lot of type-safety by using fragments, because we cannot infer the return type based on a string.


StackOverflow Bot on Twitter: "MongoError: cannot infer query fields , MongoError: cannot infer query fields to set, path 'xxx' is matched twice http:// stackoverflow.com/questions/39060861 … #mongodb #mongoose� Turned out a bit more difficult than I initially thought, which makes that I cannot fully drop simulated upserts where the mod is a replacement and where the _id has to be controlled from meteor but neither the query, nor the replacement contains an id. E.g. upsert({"foo": "bar"}, {"bar": 1}) Still dropping 2.4 is important because:


[SERVER-23632] Take field value from $setOnInsert when it cannot , Take field value from $setOnInsert when it cannot be inferred otherwise. Log In "errmsg" : "cannot infer query fields to set, path 'someField' is� Hello, I am trying to create a Flow that moves a document when a new file is created in a document library where column X has a certain value. When using a custom column (from a custom content type), I get this error: InvalidTemplate. Unable to process template language expressions for action '


Cannot infer query fields to set, both paths � Issue #459 , I hope: Project will support updating (upsert=true) with subdocment in spec query as soon as. Example: spec = { "a" : 1, "b.c.": 2, "b.d": 3 } data� This way, field-insensitive analysis over the transformed program can infer information on the original fields.


You can also write an untyped empty array using [], in which case BigQuery attempts to infer the array type from the surrounding context. If BigQuery cannot infer a type, the default type ARRAY<INT64> is used. Using generated values. You can also construct an ARRAY with generated values. Generating arrays of integers