Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any working around with Mongodb key can't contain "." or "$"?

Tags:

mongodb

This kind of document are not accepted by Mongodb:

{'.':1}

if encode and decode by hand that's a pain. Any thoughts?

like image 518
C19 Avatar asked Apr 06 '13 04:04

C19


People also ask

What are the limitations of MongoDB?

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.

What is MongoDB Index Key limit?

A collection cannot have more than 64 indexes. The length of the index name cannot be longer than 125 characters. A compound index can have maximum 31 fields indexed.

Are there keys in MongoDB?

All documents in a MongoDB collection have a primary key dubbed _id . This field is automatically assigned to a document upon insert, so there's rarely a need to provide it.

What are keys in MongoDB?

Key value databases, also known as key value stores, are database types where data is stored in a “key-value” format and optimized for reading and writing that data. The data is fetched by a unique key or a number of unique keys to retrieve the associated value with each key.


1 Answers

The Naming Restrictions on database, collection, and field names have practical purposes. They try to ensure queries are unambiguous and that valid filenames can be created.

For example:

  • MongoDB uses dot notation to access elements of an array or subdocument.

  • MongoDB uses the dollar sign ($) to represent operators (eg. $inc).

  • Database names correspond to files created in the operating system, and there are reserved characters for path separators and wildcards.

The obvious workaround (which is also suggested in the MongoDB manual) is to use a different character. For example, the Unicode full width equivalents of $ and . will display similarly but are not reserved:

  • U+FF04 (i.e. “$”)
  • U+FF0E (i.e. “.”)
like image 171
Stennie Avatar answered Dec 04 '22 19:12

Stennie