Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Escaping quotes while inserting records in MongoDB?
The double quotes have unicode which has the value \u0022. Let us first create a collection with documents −
> 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 })
Following is the query to display all documents from a collection with the help of find() method −
> db.escapingQuotesDemo.find().pretty();
This will produce the following output −
{
"_id" : ObjectId("5ccf42e2dceb9a92e6aa195b"),
"StudentFullName" : "John \" Smith"
}
{
"_id" : ObjectId("5ccf42f0dceb9a92e6aa195c"),
"StudentFullName" : "David \" Miller"
}
{
"_id" : ObjectId("5ccf42f9dceb9a92e6aa195d"),
"StudentFullName" : "John \" Doe"
}
{
"_id" : ObjectId("5ccf4303dceb9a92e6aa195e"),
"StudentFullName" : "Carol \" Taylor"
}Advertisements