How is "foo" different from foo in the mongodb key: value pair?

When I see a field: value pair as

"name":"foo" and "name":foo

What is the difference between the two? Are both values ​​strings?

What about

"age":3 and "age":"3"

Is the first whole? I'm confused.

Thank.

+3
source share
1 answer

Strings versus Variables

The following sets the string value to the "foo" property:

item = { "name" : "foo" } // item.name = "foo"

Next, the variable value is assigned foo . If the variable foodoes not exist, you will receive an error message:

item = { "name" : foo } // foo doesn't exist yet, will result in error

foo = "my value" // foo is defined here
item = { "name" : foo } // item.name = "my value"

Numbers versus Strings

Next, the property is assigned : Number

child = { "age" : 3 } // child.age = 3

Numbers can be used in all mathematical operations. For example, child.age * 3lead to 9, and child.age + 4lead to 7.

string:

child = { "age" : "3" } // child.age = "3"

. , child.age * 3 9, , child.age + 4 34 - .

, . , ( ).

+5

Source: https://habr.com/ru/post/1770855/


All Articles