Giter Club home page Giter Club logo

Comments (3)

neoxic avatar neoxic commented on May 25, 2024

It's possible. Have you read the docs before opening the issue?

https://github.com/neoxic/lua-mongo/blob/master/doc/main.md#mongobsonvalue

from lua-mongo.

cat-anna avatar cat-anna commented on May 25, 2024

Oh, I missed that adding __array is required. It's poor requirement. Few json libs I had worked with was able to handle it transparently.
I'm replacing simple json storage with mongo and data is not tagged with __array nor it will be generated with it. So it seems I have to tag arrays manually before passing to lua-mongo.

from lua-mongo.

neoxic avatar neoxic commented on May 25, 2024

It's a very powerful requirement that helps avoid ambiguity. Let's suppose you have a table {[1] = 1, [3] = 3, [5] = 5} that maps one group of IDs to another. If treated automatically, it needs to be stored as {"1": 1, "3": 3, "5": 5} in JSON/BSON. And then it happens that two pairs are added to it - [2] = 2 and [4] = 4. Oops! Your table has suddenly become an indexed array in Lua and, if treated automatically, will be stored in JSON/BSON incorrectly as [1, 2, 3, 4, 5].

On the other hand, prohibiting automatic numeric key conversions and having an explicit indexed array marker __array helps avoid a great deal to subtle bugs like that.

Furthermore, if you wish to mark your tables with __array automatically on the fly, you can always do that using the __toBSON metamethod. This way, you are free to implement any indexed array autodetection policy as you see fit. It is much more flexible than having a "one size fits all" built-in strategy for detecting indexed arrays.

from lua-mongo.

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.