# Orderasc/desc by object that is missing the field data

**URL:** https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389
**Category:** Users
**Created:** [October 11, 2018, 8:42am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389 "2018-10-11T08:42:34Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 11, 2018, 8:42am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/1 "2018-10-11T08:42:34Z")

</div>

ive some old data that did not declare field created\_at during my initial test.  
later on, i’ve inserted those fields.  
when i tried to sort by the missing field, the records only show those with this field declared. is this a norm?

i have not test with filter, what if i filter by this field with not equal?  
will those old records without this field being enter also went missing?

as seen below, the result output will defer from count

```auto
query all($nothing: string){
  
users(func: eq(_type, "users") orderdesc: created_at) {
		uid
		email
		created_at
		updated_at
}
  users_count(func: eq(_type, "users")) {
	count(uid)
}
}

```

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 11, 2018, 10:34am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/2 "2018-10-11T10:34:24Z")

</div>

ive been testing delete,  
and realize some how the data become inconsistant.  
sometimes the list shows all records, but sometimes it shows only those records with created\_at field specified

---

<div class="post-metadata">

### Author: ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)
#### Post date: [October 11, 2018, 2:27pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/3 "2018-10-11T14:27:57Z")

</div>

Hi James,

> [@u007](#):
>
> is this a norm?

Not sure, but by logic, it seems like this would happen anyway. Because Dgraph can only Sort by what is indexed. You can create a task in your application to hunt those nodes that have no date and add a generic date.

Fill in an Issue about it.

Well I did some tests on:

```auto
Dgraph version : v1.0.9
Commit SHA-1 : 22c13fce
Commit timestamp : 2018-10-02 16:45:53 -0700
Branch : HEAD

```

```auto
{
  
users(func: eq(_type, "users"), orderdesc: created_at) {
		uid
		email
		created_at
		updated_at
}
  users_count(func: eq(_type, "users")) {
	count(uid)
}
}

```

Result:

```auto
{
  "data": {
    "users": [
      {
        "uid": "0x4",
        "email": "contact@edward.com",
        "created_at": "2018-01-01T00:00:00Z",
        "updated_at": "2019-01-01T00:00:00Z"
      },
      {
        "uid": "0x5",
        "email": "contact@edward.com",
        "created_at": "2018-01-01T00:00:00Z",
        "updated_at": "2019-01-01T00:00:00Z"
      },
      {
        "uid": "0x6",
        "email": "contact@edward.com",
        "created_at": "2018-01-01T00:00:00Z",
        "updated_at": "2019-01-01T00:00:00Z"
      },
      {
        "uid": "0x7",
        "email": "contact@edward.com",
        "created_at": "2018-01-01T00:00:00Z",
        "updated_at": "2019-01-01T00:00:00Z"
      }
    ],
    "users_count": [
      {
        "count": 8
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "processing_ns": 3002300
    },
    "txn": {
      "start_ts": 22
    }
  }
}

```

Mutation was:

```auto

{
   "set":[
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com",
         "created_at":"2018",
         "updated_at":"2019"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com",
         "created_at":"2018",
         "updated_at":"2019"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com",
         "created_at":"2018",
         "updated_at":"2019"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com",
         "created_at":"2018",
         "updated_at":"2019"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com"
      },
      {
         "_type":"users",
         "name":"Edward",
         "email":"contact@edward.com"
      }
   ]
}

```

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 12, 2018, 4:40am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/4 "2018-10-12T04:40:07Z")

</div>

hi @MichelDiz

okay thank you.  
i will do the manual update for addition of new fields…

are there any mutation in dgraph based on certain filter(s) that set all nodes to the value i wish?  
for example are those without created\_at and set it to 0001-01-01 ?

thank you

---

<div class="post-metadata">

### Author: ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)
#### Post date: [October 12, 2018, 1:24pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/5 "2018-10-12T13:24:06Z")

</div>

> [@u007](#):
>
> are there any mutation in dgraph based on certain filter(s) that set all nodes to the value i wish?

Nops, but you could try to do this as an upsert procedure [Get started with Dgraph](https://docs.dgraph.io/howto/#upsert-procedure)  
may work good. Use “`has(created_at)`” instead of “eq”.

If the searched Node has “created\_at” it does nothing. If it does not, it returns the UID and you generate a mutation with it.

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 16, 2018, 8:52am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/6 "2018-10-16T08:52:45Z")

</div>

Hi @MichelDiz

okay noted, so ive to do mutation in application layer for all existing records.  
but how do i query for those field without created\_at?

---

<div class="post-metadata">

### Author: ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)
#### Post date: [October 16, 2018, 3:30pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/7 "2018-10-16T15:30:39Z")

</div>

Maybe something like this:

```auto
{
  
users(func: eq(_type, "users")) @filter(NOT has(created_at)) {
		uid
		email
		created_at #let it here just to ensure
		updated_at #let it here just to ensure
}

}

```

And then do a query for “updated\_at” just in case.

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 16, 2018, 4:02pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/8 "2018-10-16T16:02:37Z")

</div>

Awesome, thank you 🙂  
i thought its !has but didnt work 😊

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 17, 2018, 9:59am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/9 "2018-10-17T09:59:17Z")

</div>

hi @MichelDiz

i have this finding:  
with this same query, i queries this multiple times on ratel ui,  
and 50% of the time, it return results with actual data, but another 50% only return records with uid field (other records without created\_at). and i could not delete those uid only records

```auto
query all($nothing: string){
	users(func: eq(_type, "users"), first: 10, orderdesc: created_at) {
		uid
		email
		username
		password
		first_name
		last_name
		mobile_no
		office_no
		gender
		country
		confirmed_at
		locked_at
		deleted_at
		reset_token
		status
		signup_type
		online
		online_at
		ip_address
		created_at
		updated_at
		roles : with_role {
			uid
			name 
		}
		work_for : work_for {
			uid
			code
			name
			status
			country
			created_at
			updated_at 
			 
		}
	}

	users_count(func: eq(_type, "users")) @filter(has(created_at)) {
		count(uid)
	}
}

```

ok result:

```auto
{
  "data": {
    "users": [
      {
        "uid": "0xea63",
        "email": "dsfsdf@example.com",
        "username": "dsfsdf@example.com",
        "password": "",
        "first_name": "dsfsd",
        "last_name": "dsfdsf",
        "mobile_no": "4",
        "office_no": "",
        "gender": "M",
        "country": "AD",
        "confirmed_at": "0001-01-01T00:00:00+06:55",
        "locked_at": "0001-01-01T00:00:00+06:55",
        "deleted_at": "0001-01-01T00:00:00+06:55",
        "reset_token": "",
        "status": 1,
        "signup_type": "email",
        "online": 0,
        "online_at": "0001-01-01T00:00:00+06:55",
        "ip_address": "",
        "created_at": "2018-10-16T09:24:48.24963+08:00",
        "updated_at": "2018-10-16T09:25:31.91972Z"
      },
      {
        "uid": "0xea62",
        "email": "ddsfsdf@example.com",
        "username": "ddsfsdf@example.com",
        "password": "",
        "first_name": "sdfdss",
        "last_name": "dfdsd",
        "mobile_no": "2324324",
        "office_no": "",
        "gender": "M",
        "country": "",
        "confirmed_at": "0001-01-01T00:00:00+06:55",
        "locked_at": "0001-01-01T00:00:00+06:55",
        "deleted_at": "0001-01-01T00:00:00+06:55",
        "reset_token": "",
        "status": 1,
        "signup_type": "email",
        "online": 0,
        "online_at": "0001-01-01T00:00:00+06:55",
        "ip_address": "",
        "created_at": "2018-10-15T03:00:36.077012+08:00",
        "updated_at": "2018-10-16T07:26:56.430786Z",
        "roles": [
          {
            "uid": "0xc369",
            "name": "superadmin"
          },
          {
            "uid": "0xc36b",
            "name": "manager"
          },
          {
            "uid": "0xc36c",
            "name": "staff"
          }
        ]
      },
      {
        "uid": "0x2720",
        "email": "test5@test.com",
        "username": "test5@test.com",
        "password": "",
        "first_name": "sdfsdf tan",
        "last_name": "sdfdsf sdfdsf",
        "mobile_no": "2423432",
        "office_no": "",
        "gender": "M",
        "country": "MY",
        "confirmed_at": "0001-01-01T00:00:00+06:55",
        "locked_at": "0001-01-01T00:00:00+06:55",
        "deleted_at": "0001-01-01T00:00:00+06:55",
        "reset_token": "",
        "status": 0,
        "signup_type": "email",
        "online": 0,
        "online_at": "0001-01-01T00:00:00+06:55",
        "ip_address": "",
        "created_at": "2018-09-14T09:03:48.808329+08:00",
        "updated_at": "2018-10-16T05:56:07.528755Z",
        "roles": [
          {
            "uid": "0xc36b",
            "name": "manager"
          }
        ]
      },
      {
        "uid": "0x271e",
        "email": "tester@tester.com",
        "username": "tester@tester.com",
        "password": "",
        "first_name": "sdfsdfsdfdsf",
        "last_name": "sdfdsfdsf",
        "mobile_no": "3432423432",
        "office_no": "",
        "gender": "F",
        "country": "MY",
        "confirmed_at": "0001-01-01T00:00:00+06:55",
        "locked_at": "0001-01-01T00:00:00+06:55",
        "deleted_at": "0001-01-01T00:00:00+06:55",
        "reset_token": "",
        "status": 0,
        "signup_type": "email",
        "online": 0,
        "online_at": "0001-01-01T00:00:00+06:55",
        "ip_address": "",
        "created_at": "0001-01-01T00:00:00+06:55",
        "updated_at": "2018-10-16T09:25:17.077452Z",
        "roles": [
          {
            "uid": "0xc36a",
            "name": "admin"
          }
        ]
      },
      {
        "uid": "0x271f",
        "email": "test@test.com",
        "username": "test@test.com",
        "password": "",
        "first_name": "cdscdscds",
        "last_name": "tan",
        "mobile_no": "4324324324324234534",
        "office_no": "",
        "gender": "M",
        "country": "MY",
        "confirmed_at": "0001-01-01T00:00:00+06:55",
        "locked_at": "0001-01-01T00:00:00+06:55",
        "deleted_at": "0001-01-01T00:00:00+06:55",
        "reset_token": "",
        "status": 0,
        "signup_type": "email",
        "online": 0,
        "online_at": "0001-01-01T00:00:00+06:55",
        "ip_address": "",
        "created_at": "0001-01-01T00:00:00+06:55",
        "updated_at": "2018-10-16T09:23:08.259463Z"
      }
    ],
    "users_count": [
      {
        "count": 5
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 75100,
      "processing_ns": 12097800,
      "encoding_ns": 1925700
    },
    "txn": {
      "start_ts": 90490,
      "lin_read": {
        "ids": {
          "1": 4989
        }
      }
    }
  }
}

```

uid only result:

```auto
{
  "data": {
    "users": [
      {
        "uid": "0x2716"
      },
      {
        "uid": "0x2715"
      },
      {
        "uid": "0x2713"
      },
      {
        "uid": "0x2712"
      },
      {
        "uid": "0x271d"
      },
      {
        "uid": "0x2717"
      },
      {
        "uid": "0x271c"
      },
      {
        "uid": "0x271b"
      },
      {
        "uid": "0x2711"
      },
      {
        "uid": "0x2719"
      }
    ],
    "users_count": [
      {
        "count": 5
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 303600,
      "processing_ns": 13727200,
      "encoding_ns": 1918800
    },
    "txn": {
      "start_ts": 90489,
      "lin_read": {
        "ids": {
          "1": 4988
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![calummoore](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/calummoore/32/614_2.png) [@calummoore](https://discuss.dgraph.io/u/calummoore)
#### Post date: [October 18, 2018, 8:29am UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/10 "2018-10-18T08:29:00Z")

</div>

I’ve also been seeing non-deterministic results when sorted value is missing.

 ![2018-10-18%2009_13_36](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/1/17c9eec0045787db1c4cf8cd15e78f4baa82b15e.gif)

---

<div class="post-metadata">

### Author: ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)
#### Post date: [October 18, 2018, 1:53pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/11 "2018-10-18T13:53:07Z")

</div>

This seems a different case, can you fill up an issue with more details?

---

<div class="post-metadata">

### Author: ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)
#### Post date: [October 18, 2018, 4:41pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/12 "2018-10-18T16:41:26Z")

</div>

ive created an issue here:

[https://github.com/dgraph-io/dgraph/issues/2672](https://github.com/dgraph-io/dgraph/issues/2672)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)
#### Post date: [November 17, 2018, 4:41pm UTC](https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/13 "2018-11-17T16:41:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
