在 MongoDB 中插入記錄時轉義引號?
雙引號有 Unicode,其值為 \u0022。我們首先使用文件建立一個集合 −
> db.escapingQuotesDemo.insert({ "StudentFullName": "John \u0022 Smith" });
WriteResult({ "nInserted" : 1 })
> db.escapingQuotesDemo.insert({ "StudentFullName": "David \u0022 Miller" });
WriteResult({ "nInserted" : 1 })
> db.escapingQuotesDemo.insert({ "StudentFullName": "John \u0022 Doe" });
WriteResult({ "nInserted" : 1 })
> db.escapingQuotesDemo.insert({ "StudentFullName": "Carol \u0022 Taylor" });
WriteResult({ "nInserted" : 1 })以下是使用 find() 方法從集合中顯示所有文件的查詢 −
> db.escapingQuotesDemo.find().pretty();
這將產生以下輸出 −
{
"_id" : ObjectId("5ccf42e2dceb9a92e6aa195b"),
"StudentFullName" : "John \" Smith"
}
{
"_id" : ObjectId("5ccf42f0dceb9a92e6aa195c"),
"StudentFullName" : "David \" Miller"
}
{
"_id" : ObjectId("5ccf42f9dceb9a92e6aa195d"),
"StudentFullName" : "John \" Doe"
}
{
"_id" : ObjectId("5ccf4303dceb9a92e6aa195e"),
"StudentFullName" : "Carol \" Taylor"
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP