使用mongodb我試圖從其父集合(Listing)的子集合(ListingFeatures)中移除一個屬性(_id)。換句話說,我有一個Listing對象,它裏面有一個ListingFeature對象列表。 ListingFeature有一個_id屬性,我試圖刪除它。從子集合中移除屬性
這裏是我試過的命令,我認爲會的工作:
db.Listing.update({ "ListingFeatures._id": { $exists:true } }, { $unset: { "ListingFeatures._id": 1 } }, false, true);
這跑了〜30分鐘完成之前(上市有300萬條記錄),它並沒有拋出任何錯誤或提供任何某種消息表示成功或失敗,但是Listing.ListingFeatures._id屬性仍然存在。
我缺少什麼?
這裏是一個精簡的示例上市文件。最終,我想從ListingFeatures集合中刪除_id,CreateDate和UpdateDate。
{
"Address": "1080 DUNLAP ORPHANAGE RD",
"City": "Unincorporated",
"ListingFeatures": [
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Status: ACTIVE"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "County: Tipton"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Approximately 10 acre(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "2 total full bath(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "2 total half bath(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "9 total rooms"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "2 stories"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Type: General Residential"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Master Bedroom is Carpet, Full Bath, Level 1, Walk-In Closet"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Basement is Partial, Unfinished"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Pool features: Above Ground"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "2 covered parking space(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Yes car garage(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Attached parking"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Cooling features: 220 Wiring, Dual System,Cooling"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Inclusions: Cooktop, Dishwasher, Gas Cooking, Microwave, Refrigerator, Satellite Dish, Self Cleaning Oven"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Lot features: Chain Fenced, Landscaped, Level, Some Trees, Wooded"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Lot size is between 10 and 20 acres"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Utilities present: Public Water, Septic Tank"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Swimming pool(s)"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Basement"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Den"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Laundry room"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Hardwood floors"
},
{
"_id": null,
"CreateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"UpdateDate": "Sun, 03 Apr 2011 19:40:04 GMT -04:00",
"Name": "Parking features: Driveway/Pad, Garage Door Opener(s), Storage Room(s), Workshop(s)"
}
],
"ZipCode": "38011",
"_id": {
"$oid": "4d99055b1b9ba917bcef9443"
}
}
你是否還試過沒有查詢'{「ListingFeatures._id」:{$ exists:true}}'的查詢?那樣有用嗎? – proximus 2011-04-24 08:50:15
剛試過,_id屬性仍然存在:db.Listing.update({},{$ unset:{「ListingFeatures._id」:1}},false,true); – Justin 2011-04-24 14:29:22