gpt4 book ai didi

database - 语法错误 : identifier starts immediately after numeric literal – MongoDB Error

转载 作者:搜寻专家 更新时间:2023-10-30 22:25:15 27 4
gpt4 key购买 nike

我正在尝试运行这个 MongoDB 脚本:

db.test_collection.insert({ 
_id: ObjectId(7df78ad8902c),
title: ‘Mongo Db practice’,
description: ‘this class is about MongoDB’
})

并不断收到此错误:

SyntaxError: identifier starts immediately after numeric literal @(shell):1:42

我认为这与 _id 和 ObjectId(7df78ad8902c) 有关,因为当我输入 ObjectId("stringliteral") 时,错误消息会发生变化。

感谢任何帮助。

最佳答案

这样试试

db.test_collection.insert({ 
_id: ObjectId('7df78ad8902c'),
title: "Mongo Db practice",
description: "this class is about MongoDB"
})

为了最佳实践,不要添加像 7df78ad8902c 这样的 _id,它不是正确的 mongoId。您将来可能会遇到问题。

如果你有任何问题随时问

关于database - 语法错误 : identifier starts immediately after numeric literal – MongoDB Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53314860/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com