0

これは私のmongodbドキュメントです。

"_id" : ObjectId("5123731f2763c9682a000001"),
"created_on" : ISODate("2013-02-19T12:42:07.835Z"),
"currentLogin" : ISODate("2013-02-22T06:03:25.603Z"),
"email" : "xxx@test.com",
"extraPhotos" : 0,
"reqmail" : [ ],
"isActivated" : true,
"lastLogin" : ISODate("2013-02-20T05:42:15.359Z"),
"linkedAccounts" : [
    {
        "birthday" : "11/01/1984",
        "email" : "testingxxx234@gmail.com",
        "expiresIn" : "5184000",
        "expiryMailNotifFlag" : -1,
        "extraPhotos" : 0,
        "fetchFromDate" : null,
        "fetchOrder" : "oldest",
        "fetchUntilDate" : "04/11/2014",
        "locale" : "en_US",
        "optIn" : true,
        "timezone" : "5.5",
        "userID" : "100000207309657"
    }
],
"maxLinkedAccounts" : 4,
"name" : "venu wale",
"notifications" : [
    {
        "_id" : ObjectId("51275fb7389b85f222000001"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:08:23.419Z")
    },
    {
        "_id" : ObjectId("51275fe8389b85f222000002"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:09:12.385Z")
    },
    {
        "_id" : ObjectId("51276020389b85f222000003"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:10:08.275Z")
    },
    {
        "_id" : ObjectId("5127605d389b85f222000004"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:11:09.946Z")
    },
    {
        "_id" : ObjectId("51276097389b85f222000005"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:12:07.384Z")
    },
    {
        "_id" : ObjectId("512760d2389b85f222000006"),
        "type" : "limitUsed",
        "message" : "Account limit is used",
        "accID" : "100000207309657",
        "date" : ISODate("2013-02-22T12:13:06.933Z")
    }
],
"password" : "638cfc167e8431c01227e4f113ec9427821b12493ed6fd3",
"phone" : "5555555555",
"photo_updated_time" : 1361341819,
"photosProcessed" : 15,
"photosToProcess" : 400,
"plan" : {
    "type" : "photoOnly"
},
"salt" : "af8ab2f5866642f03d31aa3f4a24e25e287bedc7",
"updated_on" : ISODate("2013-02-19T12:42:07.835Z")

通知配列から任意の1つのオブジェクトを削除したい。私はこのクエリを使用しています。

db.users.update({phone: '5555555555'}、{$ unset:{notifications:{$ elemMatch:{_ id:ObjectId( '51276020389b85f222000003')}}}})

しかし、それは機能していません。

4

1 に答える 1

4

この要素を配列から取得するだけで済みます。notifications

db.collection.update({phone:"5555555555"},{$pull:{notifications: {_id:ObjectId("51276020389b85f222000003")}}})

プルを使用すると、内部クエリに一致するすべての要素を削除できます。次の $pull

{$pull:{ notifications: {type: "limitUsed"}}}

タイプ「limitUsed」のすべての通知を削除します。

于 2013-02-22T12:39:58.367 に答える