在 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