Merge data locally & offline in iOS app with RealmSwift?

I’ve searched all over the internet for a tutorial on how to merge data in Realm DB! but actually I found nothing useful, Indeed no-one created a guide or tutorial on this topic.

I want to persist a book app contents locally in app but all the tutorials are on how to save the user “new data” in app and not about persisting and merging data in app such as a book app that have many chapters and includes long text materials that the user just want to read the contents(data) . .

I found out with Realm browser you can just edit the simulator’s data and it seems there’s no way to merge a Realm DB file with your app and finally publish it in App Store!

On the other hand I’m looking for a way to import long text data and some images to Realm and merge it with my app, so when user download the app, the user be able to see data in offline mode.

Thank you all for the time you’re spending on this

Find data without repetitions multiple documents in MongoDB

Good morning, I am learning MongoDB but when trying to make a query I do not achieve the desired results.

The structure of the documents used is as follows:

use empresa

db.departamento_dos.insert (
 "Codigo": 2,
 "Nombre": "Contabilidad",
 "Presupuesto": 10000,
  "Empleado": { "DNI": "10340", "Nombre": "Andres", "Apellido": "Lopez"},
  "Empleado": { "DNI": "10341", "Nombre": "Paula", "Apellido": "Tovar"},
  "Empleado": { "DNI": "10342", "Nombre": "Andres", "Apellido": "Perez"},
  "Empleado": { "DNI": "10343", "Nombre": "Camila", "Apellido": "Perez"},
  "Empleado": { "DNI": "10344", "Nombre": "Cristian", "Apellido": "Forero"}


db.departamento_tres.insert (
 "Codigo": 77,
 "Nombre": "Marketing",
 "Presupuesto": 30000,
  "Empleado uno": { "DNI": "10350", "Nombre": "Maria", "Apellido": "Perez"},
  "Empleado dos": { "DNI": "10351", "Nombre": "Angie", "Apellido": "Gómez"},
  "Empleado tres": { "DNI": "10352", "Nombre": "Andrea", "Apellido": "Lopez"},
  "Empleado cuatro": { "DNI": "10353", "Nombre": "Cristina", "Apellido": "Riaño"},
  "Empleado cinco": { "DNI": "10354", "Nombre": "Annie", "Apellido": "Castellanos"}

My question is: how can I make a query by “Apellido” by eliminating repeated “Apellidos”?

I tried to use the different operator with a regular expression to auto-complete the query, but not work.

db.departamento_uno.distinct( "Empleados.Empleado", { /.*".Apellido"} )

and it always shows me an empty vector.

The idea is to be able to consult the two documents simultaneously. For example, the result I’m looking for would be:

[ "Lopez", "Tovar", "Perez", "Forero", "Gómez", "Riaño", "Castellanos"]

since the idea is to show each surname only once no matter how many times it appears

Any idea how you can make this query?

Thanks for the help.

mysqli_real_escape_string for int

Help, I’ve been searching for all solutions on how I can retrieve my data from a table in a database using the primary key.

intval($referenceNumber) = mysqli_real_escape_string($link, $_POST['referenceNumber']);

Then my sql query goes like this..

$sql = "INSERT INTO cleared 
        (referenceNumber, visitorName, visitorID, 
        numberOfCompanions, collegeVisit, reasonVisit, timeIn)
        SELECT *
        FROM visitor
        WHERE referenceNumber = PRIMARY KEY";`

I always get the error: Fatal error: Can’t use function return value in write context in C:\wamp64\www\test\transfer.php on line 13

How can I remove this error?
Thanks in advance for the help.

Can’t get the same order of my dataframe arranged by Date

I have a date frame arranged by Date:

> data1[order(as.Date(data1$Date)),]
      StoreType       Date   V1        V2    V3
   1:         b 2013-01-01 2401  5895.500 17267
   2:         a 2013-01-01 2907  2907.000  2907
   3:         c 2013-01-02 1198  6372.714 20493
   4:         a 2013-01-02 1402  6512.269 25357
   5:         d 2013-01-02 1816  5694.315 20355
3545:         b 2015-07-30 5625 11128.647 22253
3546:         c 2015-07-31 3377  9109.318 18690
3547:         a 2015-07-31 2726  8967.260 27508
3548:         d 2015-07-31 4239  9096.796 23996
3549:         b 2015-07-31 6975 12677.765 25774

Then I need to get my dataframe where the Date column is transformed to year-month type. So I used this:

> data1$Date<-format(as.Date(data1$Date),"%Y-%m")
> head(data1$Date)
[1] "2015-07" "2013-01" "2014-01" "2014-12" "2013-11" "2015-06"

But this is not arranged to the Ascending order. In fact the issue below should be:

  2013-01 2013-01 2013-01 2013-01 2013-01 2013-01

The same my data frame is not arranged as I need.

How can I arrange my data frame without having the risk to mix values and having no correspondance between values of v1,v2,v3 and their real dates?

thank you in advance!

Simply/automatically copy production database to localhost

Is there any way to simple replace my localhost database of selected project with production database downloaded from server?

I know on Linux I can make “mysqldump” command:

mysqldump -uroot -pMypsw -h remoteHost remoteDB | mysql -u root -pMypsw localDB

but can I do the same on Windows?

Maybe there is more comfortable way to do that:
– by software
– addon for PhpMyAdmin to do that by icon click
– batch file (?)

How to add user to database after email confirmation?

I have a website built with PHP Codeigniter framework. It has an user management system. Generally, what it does is, when an user registers, it add his information to database and sends a conformation email(like other systems).

But now some spammers are creating lots of accounts. They don’t verify the email though. Just add more records to the database. However, my database is getting heavy for this. How can I prevent this?

Is there any workflow by which I can add an user after his email confirmation?

Thanks in advance.

Getting list of all posts with user like and total likes for each post in firestore

This question is related to querying firestore and best approach for implementing like system and counting no of likes for each post in firestore.

Let us say we have collection called posts, likes, comments, hashtags. Which has json structure like this.

posts:[{                   likes [{                      
  postId:id                postId:,                       
  createdAt:date           userId,                       
  title:string,            collectionType:'posts', 
  description,string       likedAt:date
  updatedAt,date          }]    

comments:[{              hashtags [{}]
  1. What is best approach to implement like system with user comments
    along with nested replies for each comment in which improves
    efficiency and performance when we have millions of users and posts.

  2. Querying all posts with likes count on it and like whether logged in user
    like each post along with comments and comments count, fetching replies per
    comment if available.

  3. Is that my approach will work for firestore ? Or any best data modelling
    design also possible.

  4. Do we need to store hashtags in separate collection of in same collection
    i.e while create post, inside post object with hashtags array.

I’m newbie to firestore, I want to learn querying data in firestore.
On basis of my knowledge in mongodb, I want to explore in firestore. Please help me in my problem case. Any suggestions or guidance is highly appreciated.


How to implement a disjoint contraint on 1:1 relation in PostgreSQL?

I need to implement a specialization of an entity, using a 1-to-1 relation, let’s say something like this:

create table vehicles (
  vehicle_id int primary key,

create table cars (
  car_id int primary key,
  vehicle_id int references vehicles(vehicle_id),

create table bikes (
  bike_id int primary key,
  bike_id int references vehicles(vehicle_id),

Now, I would like to enforce a disjoint contraint, to make sure a vehicle can be either a car or a bike, maybe neither, but never both. As I understand, it is not easy to achieve via RDBM itself, so I decided to validate this in the application (Ruby on Rails). In this case, I think it would be easier to validate if I do the relations the other way around, as it doesn’t need any aditional selects and locks during insert:

create table vehicles (
  vehicle_id int primary key,
  car_id int references cars(car_id),
  bike_id int references bikes(bike_id),

create table cars (
  car_id int primary key,

create table bikes (
  bike_id int primary key,

Now, none of the disjoint constraints implementations I have found uses this way. Does it have any disadvantages that I can’t see?

Adding data value per query – Mysql

I wonder if this is gonna work in plain mysql query.
I have 2 columns qty and bal. In every item from quantity, it must be increase or decrease in balance just like below.

quantity | balance
10.000   | 10.000
1.000    | 11.000
-10.000  | 1.000

I tried using += assignment operator but it gives me a syntax error.

    group_concat(format(item_ledger_entry.Quantity,3)order by Posting_Date separator '\n') AS quantity
    group_concat(0+=format(item_ledger_entry.Quantity,3) order by Posting_Date separator '\n')  as bal,
    from item
    group by item.No_;

Is there a way to do this in a simpler way?