簡體   English   中英

將文檔_id從對象更改為字符串?

[英]change document _id from object to string?

目前正在使用此功能,但似乎未加載。 這只是需要一段時間還是我做錯了什么? 我的分貝是在3.0.3模上,而我的外殼是3.2.1

db.itemtemplates.find().snapshot().forEach(
  function (e) {
    // update document, using its own properties
    e._id = e._id.str
    db.itemtemplates.save(e);
  }
)

ObjectId轉換為字符串的正確方法是toString() ,請參見文檔

db.itemtemplates.find().snapshot().forEach(
  function (e) {
    // update document, using its own properties
    e._id = e._id.toString()
    db.itemtemplates.save(e);
  }
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM