Bizarre issue with insertMany() CLI command

I am using insertMany() to add data to a collection which works successfully - However, some underlying mechanism is messing up the types. When I try to use $inc on one of the documents added, it says nonnumeric type (athough the type is numberInt)

What’s most strange about this situation is that if I manually update the fields, the problem is solved. If I don’t manualy update, they don’t appear in the search results… But I update, change nothing, and voila.

For context, the documents have a field “status” which is set to 2, ($numberInt) - I have a cron constantly looking for documents with {“status”: 2} that updates status to 6 (and this never fails, except in this case, where even though status is 2 it never changes unless I ‘update’)

When I try to update in the shell, it fails with “Cannot apply $inc to a value of non-numeric type. {_id: ObjectId(’ excluded ')} has the field ‘status’ of non-numeric type object”" but even on the webapp I can see that the status field is properly set to numberInt

thanks!
:smile:

Hello @Beulr_Team, welcome to the MongoDB Community forum!

These are your questions or concerns:

  1. When I try to use $inc on one of the documents added, it says nonnumeric type (athough the type is numberInt)
  2. What’s most strange about this situation is that if I manually update the fields, the problem is solved.
  3. If I don’t manualy update, they don’t appear in the search results.
  4. I have a cron constantly looking for documents with {“status”: 2} that updates status to 6…

Please include samples of documents and the code that is producing (or not producing) the expected results, for each of the cases. How does the cron job does the updates - include the code the job runs.

Some general information about using number data types in MongoDB. By default, when using with mongo shell, a number is stored as type double. Application programs may have different data types as default (for example, Java programming language has an int as the default number type).

1 Like