Introduction
Strings and numbers store text and numeric values in a database. They help keep data organized and easy to use.
Jump into concepts and practice - no test required
Strings and numbers store text and numeric values in a database. They help keep data organized and easy to use.
{ fieldName: "string value" } or { fieldName: 123 }Strings are enclosed in double quotes.
Numbers can be integers or decimals without quotes.
{ name: "Alice" }{ age: 30 }{ price: 19.99 }{ phone: "123-456-7890" }This adds a product with a string name, a decimal price, and a number stock count. Then it shows all products.
db.products.insertOne({ name: "Notebook", price: 5.99, stock: 100 })
db.products.find({})Strings can hold letters, numbers, and symbols.
Numbers are used for math operations in queries.
Always use quotes for strings, no quotes for numbers.
Strings store text inside quotes.
Numbers store numeric values without quotes.
Use the right type to keep data clear and useful.
db.products.find({ price: 100 }){ "name": "Pen", "price": 100 }
{ "name": "Book", "price": "100" }db.users.insertOne({ "age": "30" })age stored as a number. What is wrong?{ "item": "apple", "quantity": "10" }
{ "item": "banana", "quantity": 10 }