
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Using positional operator with hierarchies in MongoDB?
Let us create a collection with documents −
> db.demo324.insertOne({"ListOfValues":[10,20,30]}); { "acknowledged" : true, "insertedId" : ObjectId("5e516349f8647eb59e562073") }
Display all documents from a collection with the help of find() method −
> db.demo324.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e516349f8647eb59e562073"), "ListOfValues" : [ 10, 20, 30 ] }
Here is the query displaying how to use positional operator −
> db.demo324.update({"ListOfValues":[10,20,30]},{ $set: { "ListOfValues.$[]": "MongoDB" } }, { upsert: true } ); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo324.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e516349f8647eb59e562073"), "ListOfValues" : [ "MongoDB", "MongoDB", "MongoDB" ] }
- Related Articles
- MongoDB pull with positional operator?
- Update a specific MongoDB document in array with $set and positional $ operator?
- Using $addFields pipeline and run with the MongoDB $filter operator
- How to query with nand operator in MongoDB?
- Write an equality in MongoDB without using $eq operator
- Select multiple values with MongoDB OR operator
- MongoDB to fetch documents with $or Operator
- How to query MongoDB using the $ne operator?
- Positional Number System
- Find values with OR operator in MongoDB and format the result.?
- MongoDB divide aggregation operator?
- Protocol and Protocol Hierarchies
- Find the exact match in array without using the $elemMatch operator in MongoDB?
- Python - Remove positional rows
- What is the $unwind operator in MongoDB?

Advertisements