這是來自MongoDB。MongoDB插入問題
我正在關注this tutorial。
我有收集如下圖所示:
$ show collections
mycol
mycollection
system.indexes
test
tutorialspoint
然後,當我試圖到集合中插入一條記錄,使用下面的語法,我得到的錯誤:
2014-04-18T08:03:55.168-0400 SyntaxError: Unexpected token ILLEGAL
db.mycol.insert({
_id: ObjectId(7df78ad8902c),
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
})
以下是來自mongodb的複製/粘貼
db.mycol.insert({
... _id: ObjectId(7df78ad8902c),
... title: 'MongoDB Overview',
... description: 'MongoDB is no sql database',
... by: 'tutorials point',
... url: 'http://www.tutorialspoint.com',
... tags: ['mongodb', 'database', 'NoSQL'],
... likes: 100
... })
2014-04-18T08:03:55.168-0400 SyntaxError: Unexpected token ILLEGAL
該示例存在缺陷,因爲ObjectId(7df78ad8902c)不是有效的JavaScript。 – JohnnyHK