pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

RxDBSchemas array of string #50

Closed Tobino closed 7 years ago

Tobino commented 7 years ago

Hi everyone,

When we are using an array of string, RXDB's collection return a wrong array.

Example:

['abc','8'] => [{0:'a',1:'b',2:'c'},{0:'8'}]

while we are expecting the same array.

example of schema:

{
  "type": "object",
  "properties": {
    "likes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}
pubkey commented 7 years ago

@Tobino I don't really get what the first example-code does/should do. Can you make an example where rxdb is involved and how you insert/fetch documents?

Tobino commented 7 years ago

Example with rxdb :

var mySchema = {
    title: 'hero schema',
    description: 'describes a simple hero',
    type: 'object',
    properties: {
        likes: {
            type: 'array',
            items: {
                type: 'string'
            }
        }
    }
};

RxDB.create('heroesDB', 'fruitdown')      // create database
    .then(function (db) { return db.collection('mycollection', mySchema); }) // create collection
    .then(function (collection) {
        collection.insert({likes: ['abc', '8']});
        collection
            .find()
            .$ // <- returns observable of query
            .subscribe(docs => {
                if (docs) {
                    console.dir(docs);
                }
            });
    });

And console.dir

{
   likes: [
      {0:'a',1:'b',2:'c'},
      {0:'8'}
   ]
}

Do you think fruitdown could be involved ?

salomonelli commented 7 years ago

Fixed with this PR.

pubkey commented 7 years ago

Fixed in version 2.0.4. Please upgrade.