Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make projections of selected attributes in mongoid?
    primarykey
    data
    text
    <p>I have Coordinate model with many markers embedded_in User model. How to extract attributes without _ids so that on output display only each lng and lat?</p> <p>structure:</p> <pre><code>{ "_id" : ObjectId( "4e9f418f1e7bf20fbc000009" ), "name" : "test", "coordinates" : [ { "lng" : 16.86783310009764, "lat" : 52.38353842845282, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000a" ) }, { "lng" : 16.85787674023436, "lat" : 52.40972501601293, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000b" ) }, { "lng" : 16.92276474072264, "lat" : 52.40071858320756, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000c" ) }, { "lng" : 16.90182205273436, "lat" : 52.38270020105396, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000d" ) }, { "lng" : 16.96705337597655, "lat" : 52.410661698108, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000e" ) }, { "lng" : 16.89495559765624, "lat" : 52.42773236584494, "_id" : ObjectId( "4e9f418f1e7bf20fbc00000f" ) } ] } </code></pre> <p>e.g.</p> <pre><code>= debug @user.coordinates.to_json </code></pre> <p>gives:</p> <pre><code>--- ! '[{"_id":"4e9f418f1e7bf20fbc00000a","lat":52.383538428452816,"lng":16.86783310009764},{"_id":"4e9f418f1e7bf20fbc00000b","lat":52.40972501601293,"lng":16.85787674023436},{"_id":"4e9f418f1e7bf20fbc00000c","lat":52.40071858320756,"lng":16.92276474072264},{"_id":"4e9f418f1e7bf20fbc00000d","lat":52.382700201053964,"lng":16.90182205273436},{"_id":"4e9f418f1e7bf20fbc00000e","lat":52.410661698108,"lng":16.967053375976548},{"_id":"4e9f418f1e7bf20fbc00000f","lat":52.42773236584494,"lng":16.894955597656235}]' </code></pre> <p>expected:</p> <pre><code>--- ! '[{"lat":52.383538428452816,"lng":16.86783310009764},{"lat":52.40972501601293,"lng":16.85787674023436},{"lat":52.40071858320756,"lng":16.92276474072264},{"lat":52.382700201053964,"lng":16.90182205273436},{"lat":52.410661698108,"lng":16.967053375976548},{"lat":52.42773236584494,"lng":16.894955597656235}]' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload