题序:上一回,咱们简单的操作了一些增减改查的操作,这一次,再来进行一场奇妙之旅
一、案例讲解
(1)、字段有值与没值时的单条数据
第一条数据title这个字段(mysql用久了,习惯这么叫了)是没有数据的,最后一条数据,是有的,按我之前操作mysql的解释,就算没有值,取数据出来,如果不限制字段名,也会出来一个null的
数据说话:
(最后一条)F:wamp64wwwxxxxxapplicationindexcontrollerTest.php:48:
array (size=5) 'name' => string '15698293845d91b208011150.92650917' (length=33)
'age' => int 0
'title' => string '现在几点了2019-09-30 15:43:04' (length=34)
'time' => int 1569829384
'id' => string '5d91b208a374a412e8000755' (length=24)
(第一条)F:wamp64wwwxxxxxapplicationindexcontrollerTest.php:48:
array (size=4) 'name' => string '15698266425d91a7521c35a4.86084823' (length=33)
'age' => int 2
'time' => int 1569826642
'id' => string '5d91a752a374a412e800074c' (length=24)
可是看到上面两条数据取出来,这就有点..........................................................................
查询全部的时候,也是这样
Array (
[0] => Array (
[name] => 15698266425d91a7521c35a4.86084823
[age] => 2
[time] => 1569826642
[id] => 5d91a752a374a412e800074c
)
[1] => Array (
[name] => 15698266435d91a7530c98f3.33312434
[age] => 1
[time] => 1569826643
[id] => 5d91a753a374a412e800074d
) ...............
[9] => Array (
[name] => 15698293845d91b208011150.92650917
[age] => 0
[title] => 现在几点了2019-09-30 15:43:04
[time] => 1569829384
[id] => 5d91b208a374a412e8000755
)
)
**后面发现一般新增字段时,要先给字段添加默认值**
如:db.fly_bill.update({}, {$set: {usableStatus: "0"}}, false, true)