top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Select tags of product collection in MongoDB?

+1 vote
183 views

I am new user of MongoDB and I use mongoDB with php.
This is my structure:

{
 "_id" : ObjectId("**********cd940c0f000029"),
 "product_name" : "HP",
 "product_description" : "Test",
 "product_brand" : "HP",
 "product_category" : "NoteBook",
 "product_tags" : [ 
   "HP", 
   "corei5"
 ]
}

Now I want to select all product tags in this collection. Please guide me to do this job.

posted Dec 10, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

$unwind (aggregation)

Definition

$unwind
Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

The $unwind stage has one of two syntaxes:

The operand is a field path:

{ $unwind: <field path> }

To specify a field path, prefix the field name with a dollar sign $ and enclose in quotes.
The operand is a document:

New in version 3.2.

{
  $unwind:
    {
      path: <field path>,
      includeArrayIndex: <string>,
      preserveNullAndEmptyArrays: <boolean>
    }
 }

For Continuous!

answer Dec 14, 2015 by Manikandan J
Similar Questions
+1 vote

I have a DB with several (quite big) collections, on Mongo 3.2.5 and WiredTiger with snappy compression on. I would like to change the compression setting on one small collection I have to test it uncompressed. Is there a possibility to do that on a secondary without having to resync the whole DB?

+1 vote

I have a project, which has 1000 images. From each image, I get 1 million documents that I currently store in a mongoDB collection.

I have 2 alternatives,
1. Create a separate collection for each image, over multiple projects, say 10 projects, and each image(collection) would have 1 million documents that will be indexed. OR
2. Have a single collection and have 1000x1,000,000 documents in one collection, which again will be indexed.

My research and reading suggests that it is not a very good idea to create 1000 collections (for each image) and create an index for each one of 1000, and go with adding a billion documents to a single collection, to which mongoDB caters with no major issue.
My main aim is to enhance performance for reading. There would be no updates and deletes. Only reads and writes. I can afford writes to be slow, but not reads. So am I right in choosing the 2nd alternative?

Any guidance is highly appreciated.

0 votes

MONGODB 3.2.8, WIREDTIGER STORAGE ENGINE
SINGLE COLLECTION HAS MORE THAN 500G, WHETHER IT NEEDS TO BE SEPARATED?

WHAT PARAMETER SHOULD BE ADJUSTED ?

...