0%

在 MongoDB 內使用 TTL

TTL == Time To Live
用於存放暫存資料
var collection = _database.GetCollection<Student>("Students");

舊的實作方法(已過時)

1
2
var index = collection.Indexes.CreateOne(Builders<Student>.IndexKeys.Ascending("expireAt"),
new CreateIndexOptions { ExpireAfter = new TimeSpan(0, 0, 20) });

新的實作方法

1
2
3
var options = new CreateIndexOptions { ExpireAfter = new TimeSpan(0, 0, 20) };
var index = new CreateIndexModel<Student>(Builders<Student>.IndexKeys.Ascending("expireAt"),options);
collection.Indexes.CreateOne(index);

Random的範圍

Random.Next(100);

0 <= x < 100

Random.Next(0,100);

0 <= x < 100

GeoLocation in MongoDb C# Driver

先記起來
https://stackoverflow.com/questions/6993249/mongodb-geospatial-index-in-c-sharp
https://stackoverflow.com/questions/17807577/how-to-create-indexes-in-mongodb-via-net
https://stackoverflow.com/questions/30829282/findall-in-mongodb-net-driver-2-0
https://stackoverflow.com/questions/33807787/mongo-db-near-query-in-c

1
2
3
var gp =new GeoJsonPoint<GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(coordinates[0], coordinates[1]));
var query=Builders<BsonDocument>.Filter.Near("Geo",gp,radius);
var result = await col.Find(query).ToListAsync();

MongoDb Import 語法暫存

1
mongoimport.exe --host <host>:10255 -u aligala0928test -p <pwd> --db PocketHiPointLocation --collection bravoEventPoints --ssl --sslAllowInvalidCertificates --type json --file "D:\MongoDB\Server\4.0\bin\Bravo.json"

紀錄一下MongoDb語法

1
2
3
db.supplyPoints.find({ Location:
{ $geoWithin:
{ $centerSphere: [ [ 121.57501, 25.07812 ], 5 / 3963.2 ] } } })
1
2
3
4
db.supplyPoints.createIndex({ Location: "2dsphere" })

var METERS_PER_MILE = 1609.34
db.supplyPoints.find({ Location: { $nearSphere: { $geometry: { type: "Point", coordinates: [ 121.57501, 25.07812 ] }, $maxDistance: 5 * METERS_PER_MILE } } })

我開心也BANG 不開心也BANG

走錯棚了,這是聖結石,不是九一一。

MongoDB BsonDateTime 轉 Datetime 記得用 .ToLocalTime()

MongoDb Api : BsonDateTime.ToLocalTime Method

下載大型Git的時候快一點

利用 depth 只下載指定版本,醬子就不用 clone 全部了。

加快大型 GIT Repository 下載速度(指定 depth)

簡單列出 C# DateTime 和 TimeSpan 的用法

糖糖先幫我記著

阿沙布魯 : 簡單列出DateTime結構與TimeSpan結構的基本用法

MSDN : TimeSpan

C# Struct 試著用

上次去聽重構的課時,有說可以考慮用 Struct ,並不會比較慢,在某些時候反而快呢!

關於網路那些事 : C# 結構(Structs) - 教學筆記 (使用visual studio)

前端好難喔Q_Q

暫存個說不定以後會用到

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-77.03238901390978, 38.913188059745586]
},
"properties": {
"title": "Mapbox DC",
"icon": "monument"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.414, 37.776]
},
"properties": {
"title": "Mapbox SF",
"icon": "harbor"
}
}]
}
},
"layout": {
"icon-image": "{icon}-15",
"text-field": "{title}",
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 0.6],
"text-anchor": "top"
}

var m = @Html.Raw(Json.Serialize(Model));
map.on('load', function () {
// Add a layer showing the places.

map.addLayer(m);

Mapbox顯示貓的圖片

https://www.mapbox.com/mapbox-gl-js/example/add-image/

平常CMD要跑的東西

  • AdminMongo
  • Hexo Folder
  • Pockethi_share for dotnet publish
  • webapi publish folder for server
  • MongoDb.exe
  • webapi Folder for dotnet publish

API 回應錯誤訊息

在寫後端時候,盡量用return Error Code的方式掌握錯誤,而不是Try-Catch

The Will Will Web : 如何自訂 ASP.NET Core Web API 的錯誤回應訊息

用Python取得多邊形面積

Python計算任意多邊形面積演算法

海龍公式要來複習一遍惹

WikiPedia : Heron’s formula

Exponential Backoff

好像是Timeout的東東
以後來研究
Microsoft Docs : Implement HTTP call retries with exponential backoff with HttpClientFactory and Polly policies

Longitude 經度; Latitude 緯度

乾 一直忘記

在Nuget安裝MongoDB.Bson的時候出現NU1605的問題

因為AspNet Core 太新了,MongoDB.Bson用到舊的元件,所以不能安裝。
在Property那邊加入忽略NU1605的錯誤即可

1
<WarningsAsErrors>NU1605</WarningsAsErrors>

Github : Build error NU1605 “Detected package downgrade” while adding a netstandart13 library

那要怎麼忽略它在csproj內呢?

StackOverflow : Warning as error - How to rid these

easy

AspNet Core 布署到Azure出現 http 502.5 的錯誤

錯誤的情況很多種,
最好的辦法就是Azure web api網址加上 scm,
使用CMD進入wwwroot然後 dotnet xxxx.dll ,
來看發生啥錯誤。

我的錯誤是有一個資料夾忘記放入,
導致讀取失敗而無法build成功。
要把該資料夾打包成zip丟上kudu內,
但有個 Support for more than 199 items 的錯誤,
這時需打開瀏覽器F12,Console輸入

window.localStorage['maxViewItems'] = 210

將暫存放大一些可解決此問題。
Github : Support for more than 199 items

Saddddddnesssss 憂傷的星期一

沒4

EntityFramework Delete一筆資料

Github : Delete a single record from Entity Framework?

OverPass API 語法暫存

用這個網址資料是最新最正確的: http://overpass-turbo.eu/
但沒有Https捏,哈豬咖西捏
另一個資料整個五年前吧: https://overpass.nchc.org.tw/overpass-turbo/
沒4別用

1
2
3
4
5
6
7
8
9
10
11
12
[timeout:900];
area["ISO3166-1"="TW"]->.searchArea;
(
//node(1762782394);
node["leisure" = "park"](area.searchArea);
way["leisure" = "park"](area.searchArea);
relation["leisure" = "park"](area.searchArea);
);

>; //把所有way的節點都列出在上面,但無詳細資訊

out meta;

ISO3166-1 原來是這玩意兒

Wikipedia : ISO_3166-1

OverPass Api 網址用誰兒

https://wiki.openstreetmap.org/wiki/Overpass_API

C#處理string內要有”上引號”

StackOverflow : How to include quotes in a string

全國的公園綠地在哪兒

政府資料開放平台 : 全國禁菸場所-公園綠地

暫存個

https://www.mapbox.com/api-documentation/?language=Python#geocoding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{{geocodeArea:ROC}}->.searchArea;
// gather results
(
// node["tourism"="museum"](area.searchArea);
//way["tourism"="museum"](area.searchArea);
//relation["tourism"="museum"](area.searchArea);
// node["shop"](area.searchArea);
// node["park"](area.searchArea);

// node["leisure" = "park"](area.searchArea);
// way["leisure" = "park"](area.searchArea);
// relation["leisure" = "park"](area.searchArea);
// node["brand" ~ "YouBike"](area.searchArea);
node["shop" = "department_store"](area.searchArea);
way["shop" = "department_store"](area.searchArea);
relation["shop" = "department_store"](area.searchArea);
node["shop" = "mall"](area.searchArea);
way["shop" = "mall"](area.searchArea);
relation["shop" = "mall"](area.searchArea);

);

overpass api 找公司附近的便利商店 並 Import 到 MongoDb 內##

overpass api
https://overpass.kumi.systems/api/interpreter
wiki

1
2
3
4
5
6
//[out:json][timeout:25];
(
node["shop"="convenience"](25.07,121.56,25.09,121.58);
<;
);
out body;

出來的會是xml file 試著轉成geoJSON
在overpass的網頁上可以直接轉
https://overpass.nchc.org.tw/overpass-turbo/

轉完後還無法用mongoimport
只需要features內的值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"type": "FeatureCollection",
"generator": "overpass-turbo",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.",
"timestamp": "",
"features": [
{
"type": "Feature",
"id": "node/1837853348",
"properties": {
"@id": "node/1837853348",
"history": "retrieved using undelete JOSM plugin",
"name": "全家",
"shop": "convenience"

...
...
...

可利用 jq 工具 轉成所需的json file
How to import Geojson file to MongoDB

1
2
3
jq --compact-output ".features" input.geojson > output.geojson

mongoimport --db dbname -c collectionname --file "output.geojson" --jsonArray

完成啦~

MongoDb Query 查詢 一次顯示的資料筆數變多 不用再it it it

1
DBQuery.shellBatchSize = 300

here

mongoimport

https://docs.mongodb.com/manual/reference/program/mongoimport/

Overpass暫存一些語法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// query part for: “shop”
node["shop"="convenience"](25.07,121.56,25.09,121.58);
way["shop"]({{bbox}});
relation["shop"]({{bbox}});
node["shop"="department store"]({{bbox}});
node["shop" = "mall"]({{bbox}});
node["construction:shop" = "department store"]({{bbox}});
node["shop" = "department_store"]({{bbox}});
node["shop"]({{bbox}}) && node["shop" = "department_store"]({{bbox}});

{{geocodeArea:Taiwan}}->.searchArea;
// gather results
(
// query part for: “tourism=museum”
node["tourism"="museum"](area.searchArea);
way["tourism"="museum"](area.searchArea);
relation["tourism"="museum"](area.searchArea);
);

Dotnet-cli

dotnet publish
dotnet xxxx.dll –server.urls=”192.168.XX.XX:15390”

Bind 起來

https://weblog.west-wind.com/posts/2017/Dec/12/Easy-Configuration-Binding-in-ASPNET-Core-revisited

找所有Files起來

https://stackoverflow.com/questions/12332451/list-all-files-and-directories-in-a-directory-subdirectories

這個神了 AutoMapper各式各樣用法

https://www.cnblogs.com/caoyc/p/6367828.html

git commit rename

https://git-scm.com/book/zh-tw/v1/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%AF%AB%E6%AD%B7%E5%8F%B2

Bizspark Azure 無法開通

一直出現 We were unable to find your Azure tenant
GOOGLE後似乎有解決辦法
here
星期二明天來44看

Time is up

時間開壓
壓起來壓起來