Giter Club home page Giter Club logo

Comments (9)

AntonSotirov avatar AntonSotirov commented on July 18, 2024

There is an issue with this implementation as well. It still doesn't behave as the original mongodb specification is.

For reference here are the tests for the $slice in mongodb jstests code.

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

Yes. The reason for reopening the issue. Updating with a fix and some test cases.

from mingo.

AntonSotirov avatar AntonSotirov commented on July 18, 2024

There is one more issue with $slice. It currently excludes all other fields from the document.
$slice should just affect the property that is being "sliced", and not interfere in any way with the exlusion or inclusion of other fields.

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

can you provide an example of this behaviour. MongoDB only includes the projected fields in the result.

from mingo.

AntonSotirov avatar AntonSotirov commented on July 18, 2024

Sure.

Example document:
{
Text: "MyText",
Array: [1,2,3]
}

Fetching this document with a fields expression of:
{
Array: { $slice: 1 }
}

should return
{
Text: "MyText",
Array: [1],
_id: <....>
}

Notice that the Text and _id field will be included.
Furthermore, you can mix $slice with field exclusion and inclusion without affecting them:

Ex.
{
Array: { $slice: 1 },
Text: 0
}

{
Array: { $slice: 1 }
Text: 1,
_id: 0
}

etc.

Current implementation of mingo returns only the Array field when $slice is used.

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

Thanks. I am a bit surprised. This looks like a special case in MongoDB. The other projection operator $elemMatch does not behave the same way.

from mingo.

AntonSotirov avatar AntonSotirov commented on July 18, 2024

That IS surprising. Didn't know about $elemMatch. I would have expected that it works the same as $slice.

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

anyway. I have a fix coming up.

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

issue resolve in release 0.3.3

from mingo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.