Giter Site home page Giter Site logo

Comments (4)

gauravbordoloi avatar gauravbordoloi commented on June 16, 2024 1

Hi @ironage
Understood and yeah the other table will work for me. Thank you. You can close the issue.

from realm-js.

ironage avatar ironage commented on June 16, 2024

Hi @gauravbordoloi we don't currently support sorting or distinct on a collection. What do you expect the behaviour of distinct to be, given dictionaries with the following sets of keys: {a, b, c}, {a, b}, {c}? When talking about comparing collections, we usually need to specify the match behaviour: ANY/ALL/NONE. So then we might be looking for syntax like DISTINCT(ALL attributes)? Is that the feature you are looking for?

from realm-js.

gauravbordoloi avatar gauravbordoloi commented on June 16, 2024

Hi @ironage , I have multiple data like these,

[
    {
        "name": "Levis Shirt",
        "attributes": {
            "color": "White",
            "size": "XL"
        }
    },
    {
        "name": "Nike Shirt",
        "attributes": {
            "color": "Red",
            "size": "L"
        }
    },
    {
        "name": "Adidas Shirt",
        "attributes": {
            "color": "Black",
            "size": "XXL"
        }
    }
]

What I want to do is

  1. fetch all the attribute keys without duplicates - Result (color, size)
  2. fetch all the attribute values for a particular key without duplicates- Result (color=White,Red,Black)

2nd point, I am able to get the data using the query
//attr = "color"
realm.objects(ProductModel).filtered(`status == $0 DISTINCT(attributes['${attr}'])`, "PUBLISH")

but for the 1st point, nothing is working. I tried the below code but it doesn't work
realm.objects(ProductModel).filtered(`status == $0 DISTINCT([email protected]`, "PUBLISH")

from realm-js.

ironage avatar ironage commented on June 16, 2024

@gauravbordoloi we don't currently support the query you are trying to do. Fundamentally, our query system produces matching objects, not a collection of matching properties. I think what you want is an advanced use of projections.
A solution for you today would be to also insert your keys into an independent class that tracks unique keys. So every time you insert into the attribute dictionary, you could also call
realm.create("AllKeys", {_id: "myKey"}, UpdateMode.Modified); // UpdateMode.Modified makes this an upsert
Insertion/lookup is fast because a primary key is indexed. Then to get all keys, you iterate over all objects of this class
realm.objects("AllKeys");
Would this work for you?

from realm-js.

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.