Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MongoDB

Escape dấu nháy kép khi insert record trong MongoDB?

Dấu nháy kép có Unicode \u0022. Tạo collection với dữ liệu chứa dấu nháy:

> 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 })

Hiển thị tất cả:

> db.escapingQuotesDemo.find().pretty();

Kết quả (dấu nháy được escape hiển thị):