SORU
25 EKİM 2010, PAZARTESİ


Nasıl bir MongoDB Belgenin _ıd güncelleme?

Bir belgenin _ıd bir MongoDB güncellemek istiyorum. Gerçekten iyi bir uygulama olmadığını biliyorum. Ama bazı teknik nedenle, güncellemek istiyorum. Eğer güncelleme yaparsam var :

> db.clients.update({'_id':ObjectId("4cc45467c55f4d2d2a000002")}, {'$set':{'_id':ObjectId("4c8a331bda76c559ef000004")}});
Mod on _id not allowed

Ve güncelleme yapılmış değil. Gerçekten nasıl update edebilirim ?

CEVAP
25 EKİM 2010, PAZARTESİ


Bu güncelleme yapamazsınız. Belge _id, yeni bir kullanarak kaydedin ve eski belge kaldırın.

// store the document in a variable
doc = db.clients.findOne({_id: ObjectId("4cc45467c55f4d2d2a000002")})

// set a new _id on the document
doc._id = ObjectId("4c8a331bda76c559ef000004")

// insert the document, using the new _id
db.clients.insert(doc)

// remove the document with the old _id
db.clients.remove({_id: ObjectId("4cc45467c55f4d2d2a000002")})

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • infiniTuts

    infiniTuts

    18 Ocak 2012
  • Munchkin the Teddy Bear

    Munchkin the

    30 EYLÜL 2011
  • ::..ηєѕѕ мιχ..::

    ::..ηєѕѕ

    15 Aralık 2006