Question

Need some pointers on how to run this query. In my controller, I'm trying to find all elements where the slug = a particular value.

Example, find all items in the collection where the slug = rockstar

Note, that their can be an array of objects under the topics, and am storing the collection in MongoDb.

The collection looks like:

{
    "createdAt": {
        "$date": 1382721247000
    },
    "updatedAt": null,
    "topics": [
        {
            "topic": "Rock Star",
            "slug": "rock-star"
        },
        {
            "topic": "Playstation",
            "slug": "playstation"
        }
    ],
    "keywords": [
        {
            "keyword": "gtav"
        }
    ]
}
Était-ce utile?

La solution

I don't think model has support for this yet (querying inside object values) because it is a mongodb specific capability.

In any case, performing a query in this manner is probably going to be very slow.

I suggest creating a "Slug" model and using a through association to map them to your model.

This way you can find the slug and load the posts that belong to that slug. Much more efficient, and also fully supported by model.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top