1

I'm digging around a MongoDB oplog, and I'm wanting to look at all operations that match the following:

"o" : {
    "$set" : {
        "skus.0.stock" : 1
    }
}

The operation in question updates an object similar to this:

{
    skus: [
        {
            stock: Number
        },
        {
            stock: Number
        },
    ]
}

The above oplog operation is $seting the stock level of an object on the skus array.

The problem is when I execute .find({"o.$set.skus.0.stock": {$exists: true}}) I get nothing back. mongo shell is expecting an object that looks like this:

"o" : {
    "$set" : {
        "skus" : {
            "0": {
               stock" : 1
            }
        }
    }
}

I took a look at this question, but the top answer basically just substitutes the period for a similar unicode character. In this case, the oplog has already inserted an actual period in to the field name.

Bracket notation throws an error a syntax error without quotes, and doesn't return anything with quotes (it just doesn't work.)

Community
  • 1
  • 1
rtf
  • 724
  • 3
  • 15
  • 27
  • 1
    As per the MongoDB Limits documentation, field names should not have the "." character in them: https://docs.mongodb.org/manual/reference/limits/#Restrictions-on-Field-Names – James Wahlin Jan 07 '16 at 21:34
  • @James As per my question: the oplog has already inserted an actual period in to the field name. Should I file a bug report? – rtf Jan 07 '16 at 22:27
  • Updated to clarify that the oplog document reflects a $set operation on an array, not a field name on my document. – rtf Jan 07 '16 at 22:31
  • And there's the bug report https://jira.mongodb.org/browse/SERVER-21889 :) – rtf Jan 07 '16 at 22:37

0 Answers0